package hnlg.com.cn.systemmanage.qibiemanage.control;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import hnlg.com.cn.common.RespBean;
import hnlg.com.cn.model.QibieVo;
import hnlg.com.cn.systemmanage.qibiemanage.service.IQibieService;

@RestController
@RequestMapping("/qibieControl")
public class QibieManageControl {
RespBean rb=null;
List<QibieVo> list=null;
@Resource IQibieService QibieService;
//http://localhost:8044/test/qibieControl/addqibie?name=第一期
@RequestMapping("/addqibie")

public RespBean addqibie(QibieVo vo){
	try{
		QibieService.addQibie(vo);
		rb=new RespBean("msg","添加成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","添加失败");
	}
	return rb;
}
//http://localhost:8044/test/qibieControl/deleteqibie?id=6
@RequestMapping("/deleteqibie")
public RespBean deleteqibie(@RequestParam("id") String id){
	try{
		System.out.println("id=="+id);
		QibieService.deleteQibie(id);
		rb=new RespBean("msg","删除成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","删除失败");
	}
	return rb;
}
//http://localhost:8044/test/qibieControl/updateqibie?id=5&name=第一期
@RequestMapping("/updateqibie")
public RespBean updateqibie(QibieVo vo){
	try{
		boolean flag=QibieService.updateQibie(vo);
		System.out.println("==="+flag);
		rb=new RespBean("msg","更新成功");
	}catch(Exception e){
		e.printStackTrace();
		rb=new RespBean("msg","更新失败");
	}
	return rb;
}

//http://localhost:8044/test/qibieControl/queryqibie?
@RequestMapping("/queryqibie")
public List<QibieVo> queryqibie(
@RequestParam(required=false,defaultValue="") String name){
	try{
		QibieVo vo=new QibieVo();
		vo.setName(name);
		list=QibieService.queryqibie(vo);
	}catch(Exception e){
		e.printStackTrace();
	}
	return list;
}

//http://localhost:8044/test/qibieControl/deletebatch?ck=1,2,3,4
@RequestMapping("/deletebatch")
public RespBean deletebatch(@RequestParam("ck") String mycheckbox[]){
	try{
		for(String obj:mycheckbox){
			System.out.println("mycheckbox=="+obj);
		}
		this.QibieService.deletebatch(mycheckbox);
		 rb= new RespBean("success", "批量删除成功");
	}catch(Exception e){
		 rb= new RespBean("success", "批量删除失败");
		e.printStackTrace();
	}
	return rb;
}
}
